home *** CD-ROM | disk | FTP | other *** search
/ US Department of Defense…ndamentals 1.0 2004 April / US Department of Defense: Firewall & Router Fundamentals 1.0 2004 April.iso / sco / includes / sco_functions.js < prev    next >
Encoding:
Text File  |  2003-10-07  |  12.0 KB  |  483 lines

  1. function initialize_page()
  2. {
  3.   //figure next and previous page URLs
  4.  
  5.   //DO NEXT PAGE
  6.   //get page type for course
  7.   var tmp_page_type = API_WIN.PAGE_TYPE;
  8.   //convert next page num into padded str
  9.   var tmp_page_str = convert_num_to_str(PAGE_NUM + 1);
  10.   if (API_WIN.RUN_REVIEW) {
  11.     tmp_page_str = convert_num_to_str(parseFloat(parse_string(REVIEW_PAGES,",",PAGE_NUM + 1)));
  12.   }
  13.   tmp_page_type = API_WIN.get_page_type(tmp_page_str,tmp_page_type,LIST_FLASH_PAGES,LIST_HTML_PAGES);
  14.   NEXT_PAGE = PATH_EXT + API_WIN.get_content_url(tmp_page_str,tmp_page_type);
  15.  
  16.   //DO PREVIOUS PAGE
  17.   //get page type for course
  18.   tmp_page_type = API_WIN.PAGE_TYPE;
  19.   //convert prev page num into padded str
  20.   tmp_page_str = convert_num_to_str(PAGE_NUM - 1);
  21.   if (API_WIN.RUN_REVIEW) {
  22.     tmp_page_str = convert_num_to_str(parseFloat(parse_string(REVIEW_PAGES,",",PAGE_NUM - 1)));
  23.   }
  24.   tmp_page_type = API_WIN.get_page_type(tmp_page_str,tmp_page_type,LIST_FLASH_PAGES,LIST_HTML_PAGES);
  25.   PREV_PAGE = PATH_EXT + API_WIN.get_content_url(tmp_page_str,tmp_page_type);
  26.  
  27.   if (PAGE_NUM == 1)  {
  28.       PREV_PAGE = "close";
  29.     DISABLE_PREV = true;
  30.   }
  31.   if (PAGE_NUM == MAX_PAGE_NUM)  {
  32.       NEXT_PAGE = "close";
  33.     if (AUTO_COMPLETION)
  34.       SCO_STATUS = "c";
  35.   }
  36. }
  37.  
  38. function start_page()
  39. {
  40.   if (RUNNING_QUEST)  {
  41.     DISABLE_PREV = true;
  42.     DISABLE_NEXT = true;
  43.   }
  44. /*
  45.   if (!RUN_508)  {
  46.     if (DISABLE_NEXT)
  47.           document.NEXT.src = NEXT_DE.src;
  48.       else
  49.         document.NEXT.src = NEXT_DEF.src;
  50.  
  51.       if (DISABLE_PREV)
  52.           document.PREVIOUS.src = PREVIOUS_DE.src;
  53.       else
  54.           document.PREVIOUS.src = PREVIOUS_DEF.src;
  55.   }
  56.   */
  57.   LOAD_DONE = true;
  58.  
  59.   if ((ENABLE_AUDIO) && (PAGE_TYPE == "flash")) {
  60.     if ("undefined" != typeof document.flashplayer.focus) {
  61.       document.flashplayer.focus();
  62.     }
  63.   }
  64.  
  65.   //show audio narrative
  66.   show_audio();
  67.  
  68.   //send bookmark, if not running question or review
  69.   if ((!API_WIN.RUN_REVIEW) && (!RUNNING_QUEST))
  70.     API_WIN.set_sco_status(PAGE_NUM,SCO_STATUS);
  71.     
  72.   //make sure window is right size if in a frame
  73.   if (API_WIN.WIN_TYPE == "frame")  {
  74.     API_WIN.resize_window(window,window.parent);
  75.   }
  76. }
  77.  
  78. function replay_page()
  79. {
  80.   window.location.reload();
  81. }
  82.  
  83. function exit_page()
  84. {
  85.   API_WIN.close_child_windows("exit_page");
  86. }
  87.  
  88. function goto_page(page,direction)
  89. {
  90.     if ((DISABLE_NEXT == true && direction == "next") || (DISABLE_PREV == true && direction == "previous")) {
  91.     //nothing
  92.         //alert("You can not continue at this point. Please try a different option.");
  93.   }
  94.     else  {
  95.         if (page == "close")  {
  96.             if (API_WIN.WIN_TYPE == "new_window")
  97.         window.close();
  98.       if (API_WIN.WIN_TYPE == "current_window")
  99.         goto_menu();
  100.       if (API_WIN.WIN_TYPE == "frame")  {
  101.         API_WIN.sco_finish();
  102.         window.location.href="about:blank";
  103.       }
  104.     }
  105.         else  {
  106.       if (page != "")
  107.         window.location.href = page;
  108.     }
  109.     }
  110. }
  111.  
  112. function goto_next_page()
  113. {
  114.   //going to course page or question page?
  115.   if ((RUN_QUEST) || (RUNNING_QUEST))  {
  116.     //are we already in a question?
  117.     if (RUNNING_QUEST)  {
  118.       goto_next_question();
  119.     }
  120.     else  {
  121.       //increment opener PAGE_NUM
  122.       goto_page("questions/start.htm","");
  123.     }
  124.   }
  125.   else  {
  126.     if (!DISABLE_NEXT)  {
  127.       //increment opener PAGE_NUM or REVIEW_PAGE_NUM
  128.       if (API_WIN.RUN_REVIEW)
  129.         opener.REVIEW_PAGE_NUM += 1;
  130.       else
  131.         API_WIN.PAGE_NUM += 1;
  132.       goto_page(NEXT_PAGE,'next');
  133.     }
  134.   }
  135. }
  136.  
  137. function goto_prev_page()
  138. {
  139.   //are we running a question? if so previous not allowed
  140.   if ((!RUNNING_QUEST) && (!DISABLE_PREV)) {
  141.     //decrement opener PAGE_NUM or REVIEW_PAGE_NUM
  142.     if (API_WIN.RUN_REVIEW)
  143.       opener.REVIEW_PAGE_NUM -= 1;
  144.     else
  145.       API_WIN.PAGE_NUM -= 1;
  146.     goto_page(PREV_PAGE,'previous');
  147.   }
  148. }
  149.  
  150. function goto_menu()
  151. {
  152.   if ((API_WIN.FILE_LMS) || (API_WIN.RUN_TYPE == "flms"))
  153.     API_WIN.flms_sco_finish('../menu.htm');
  154.   else  
  155.     window.close();
  156. }
  157.  
  158. function goto_spec_page(page_num,force_nav_rules)
  159. {
  160.   if (!isNaN(page_num)) {
  161.     if (API_WIN.RUN_REVIEW) {
  162.       alert("This functionality is not supported in the Review Mode.");
  163.     }
  164.     else  {
  165.       page_num = parseFloat(page_num);
  166.       if ((page_num >= 1) && (page_num <= MAX_PAGE_NUM))  {
  167.         var page_str = convert_num_to_str(page_num);
  168.         var page_type = API_WIN.get_page_type(page_str,API_WIN.PAGE_TYPE,LIST_FLASH_PAGES,LIST_HTML_PAGES);
  169.         var page_url = PATH_EXT + API_WIN.get_content_url(page_str,page_type);
  170.         if (force_nav_rules)  {
  171.           if ((page_num > PAGE_NUM) && (!DISABLE_NEXT))  {
  172.             API_WIN.PAGE_NUM = page_num;
  173.             goto_page(page_url,"");
  174.           }
  175.           if ((page_num < PAGE_NUM) && (!DISABLE_PREV))  {
  176.             API_WIN.PAGE_NUM = page_num;
  177.             goto_page(page_url,"");
  178.           }
  179.         }
  180.         else  {
  181.           API_WIN.PAGE_NUM = page_num;
  182.           goto_page(page_url,"");
  183.         }
  184.       }
  185.     }
  186.   }
  187. }
  188.  
  189. function enable_next(bln_temp)
  190. {
  191.   DISABLE_NEXT = !bln_temp;
  192.   if (document.NEXT) {
  193.     if (DISABLE_NEXT) {
  194.       document.NEXT.src = NEXT_DE.src;
  195.     }
  196.     else {
  197.       document.NEXT.src = NEXT_DEF.src;
  198.     }
  199.     if (ORIG_IMG) {
  200.       if (ORIG_IMG.name == "NEXT") {
  201.         ORIG_IMG.src = document.NEXT.src;
  202.       }
  203.     }
  204.   }
  205. }
  206.  
  207. function enable_previous(bln_temp)
  208. {
  209.   DISABLE_PREV = !bln_temp;
  210.   if (document.PREVIOUS) {
  211.     if (DISABLE_PREV) {
  212.       document.PREVIOUS.src = PREVIOUS_DE.src;
  213.     }
  214.     else {
  215.       document.PREVIOUS.src = PREVIOUS_DEF.src;
  216.     }
  217.     if (ORIG_IMG) {
  218.       if (ORIG_IMG.name == "PREVIOUS") {
  219.         ORIG_IMG.src = document.PREVIOUS.src;
  220.       }
  221.     }
  222.   }
  223. }
  224.  
  225. function set_status(sub_sco,status)
  226. {
  227.   API_WIN.flms_set_sco_status(API_WIN.flms_get_cur_sco(),sub_sco,status);
  228. }
  229.  
  230. function set_location(sub_sco,location)
  231. {
  232.   API_WIN.flms_set_sco_loc(API_WIN.flms_get_cur_sco(),sub_sco,location);
  233. }
  234.  
  235. function flash_next()
  236. {
  237.   if (!DISABLE_NEXT)
  238.     FN_TIMER = setInterval("hacked_fn();",1000);
  239. }
  240.  
  241. function hacked_fn()
  242. {
  243.   if (FN_TIMER != "")
  244.     clearInterval(FN_TIMER);
  245.   document.NEXT.src = NEXT_FLASH.src;
  246. }
  247.  
  248. function open_review(review_pages)
  249. {
  250.   if (API_WIN.RUN_REVIEW) {
  251.     alert("This functionality is not supported in the Review Mode.");
  252.   }
  253.   else  {
  254.     //set REVIEW_PAGES
  255.     API_WIN.RUN_REVIEW = true;
  256.     REVIEW_PAGES = review_pages;
  257.     REVIEW_PAGE_NUM = 1;
  258.     REVIEW_PAGE = parseFloat(parse_string(REVIEW_PAGES,",",PAGE_NUM));
  259.     if (REVIEW_PAGE > 0)  {
  260.       var tmp_page_str = convert_num_to_str(REVIEW_PAGE);
  261.       var tmp_page_type = API_WIN.get_page_type(tmp_page_str,API_WIN.PAGE_TYPE,LIST_FLASH_PAGES,LIST_HTML_PAGES);
  262.       var tmp_page_url = PATH_EXT + API_WIN.get_content_url(tmp_page_str,tmp_page_type);
  263.       API_WIN.RV_WIN=open(tmp_page_url,"REVIEWWIN","location=no,scrollbars=no,resizeable=no,width=" + MEDIA_WIDTH + ",height=" + (parseInt(MEDIA_HEIGHT) + parseInt(RV_WIN_OFFSET)) + ",toolbar=no,directories=no,menubar=no,status=yes,");
  264.       API_WIN.RV_WIN.focus();
  265.     }
  266.   }
  267. }
  268.  
  269. function open_popup(page_url,left,top,width,height,scroll,resize,menu)
  270. {
  271.   API_WIN.open_popup(page_url,left,top,width,height,scroll,resize,menu);
  272. }
  273.  
  274. function open_glossary(term)
  275. {
  276.   API_WIN.open_glossary(term);
  277. }
  278.  
  279. function open_prefs()
  280. {
  281.   API_WIN.open_prefs();
  282. }
  283.  
  284. function open_refs()
  285. {
  286.   API_WIN.open_refs();
  287. }
  288.  
  289. function open_help()
  290. {
  291.   //API_WIN.open_help();
  292.   alert("Help is not available yet.");
  293. }
  294.  
  295. function open_map()
  296. {
  297.   API_WIN.flms_sco_finish('../map.htm');
  298. }
  299.  
  300. function show_audio()
  301. {
  302.   if (SHOW_AUDIO) {
  303.     if (PAGE_NUM > 0)
  304.       API_WIN.open_audio_win(API_WIN.get_audio_url(PAGE_STR));
  305.   }
  306.   else if (API_WIN.AUDIO_WIN != null) {
  307.     API_WIN.AUDIO_WIN.close();
  308.     API_WIN.AUDIO_WIN = null;
  309.   }
  310. }
  311.  
  312. function toggle_audio()
  313. {
  314.   if (SHOW_AUDIO) {
  315.     document.AUDIO.src = AUDIO_OFF.src;
  316.     set_cookie_value('showaudio','0');
  317.     opener.SHOW_AUDIO = false;
  318.     SHOW_AUDIO = false;
  319.   }
  320.   else {
  321.     document.AUDIO.src = AUDIO_ON.src;
  322.     set_cookie_value('showaudio','1');
  323.     opener.SHOW_AUDIO = true;
  324.     SHOW_AUDIO = true;
  325.   }
  326.   show_audio();
  327. }
  328.  
  329. function switch_lang()
  330. {
  331.   var tmp_iso_lang = "en";
  332.   if (ISO_LANG == "en")
  333.     tmp_iso_lang = "es";
  334.  
  335.   //set it in API window
  336.   API_WIN.set_lang(tmp_iso_lang);
  337.  
  338.   replay_page();
  339. }
  340.  
  341. function goto_next_question()
  342. {
  343.   //make sure questions are there
  344.   if (MAX_QUEST_NUM == 0) {
  345.     //problem
  346.     alert("This Quiz has not been setup correctly. Contact your system administrator.");
  347.   }
  348.   else  {
  349.     //if asked all questions, go back to next page in course
  350.     if (QUEST_NUM >= MAX_QUEST_NUM)  {
  351.       RUN_QUEST = false;
  352.       RUNNING_QUEST = false;
  353.       goto_next_page();
  354.     }
  355.     else  {
  356.       //show next question
  357.       var quest_id = 0;
  358.       var rand_num = 0;
  359.       var quest_list = QUEST_LIST;
  360.       var search_str = ",";
  361.       while (quest_list.indexOf(search_str,0) > -1) {
  362.         //get a random question id
  363.         rand_num = Math.random();
  364.         quest_id = Math.round(rand_num*(QUEST_POOL_NUM-1)) + 1;
  365.         search_str = "," + quest_id + ",";
  366.       }
  367.       //add question to quest list
  368.       API_WIN.QUEST_LIST = quest_list + quest_id + ",";
  369.       //incement question number
  370.       API_WIN.QUEST_NUM += 1;
  371.       //go to next question
  372.       goto_page("question" + convert_num_to_str(quest_id) + ".htm","next");
  373.     }
  374.   }
  375. }
  376.  
  377.  
  378. //quiz stuff - test version, provides feedback and moves to next page
  379. function check_answer_test(answer_obj)
  380. {
  381.     var ans_list = ANSWER_LIST;
  382.   var quest_id = PAGE_NUM;
  383.   if (QUEST_NUM > 0)
  384.     quest_id = QUEST_ID;
  385.     var search_str = "," + quest_id + ",";
  386.     if ((ans_list == "") || (ans_list.indexOf(search_str,0) == -1))
  387.     {
  388.         opener.ANSWER_LIST = ans_list + quest_id + ",";
  389.     var correct_ans_value = correct_ans(answer_obj,quest_id);
  390.       var correct_ans_obj = eval("document.form1." + correct_ans_value);
  391.       if ((correct_ans_value != "") && (answer_obj.name == correct_ans_value))  {
  392.       //increment correct_answer counter
  393.       opener.CORRECT_ANSWERS += 1;
  394.           do_feedback(correct_ans_obj,true,false);
  395.     }
  396.       else
  397.           do_feedback(correct_ans_obj,false,false);
  398.     }
  399.     else
  400.         alert ("You've already answered this question!");
  401.  
  402.     //navigate to next question
  403.   DISABLE_NEXT = false;
  404.     goto_next_page();
  405. }
  406.  
  407. //quiz stuff - quiz version, provides feedback, if correct moves to next page
  408. function check_answer_quiz(answer_obj)
  409. {
  410.   var correct_ans_value = correct_ans(answer_obj,QUEST_ID);
  411.   var correct_ans_obj = eval("document.form1." + correct_ans_value);
  412.   if ((correct_ans_value != "") && (answer_obj.name == correct_ans_value))  {
  413.     do_feedback(correct_ans_obj,true,true);
  414.     DISABLE_NEXT = false;
  415.     goto_next_page();
  416.   }
  417.   else  {
  418.     do_feedback(correct_ans_obj,false,true);
  419.     answer_obj.checked = false;
  420.   }
  421. }
  422.  
  423. function do_feedback(correct_ans_obj,correct,use_default)
  424. {
  425.   if (SHOW_FEEDBACK)  {
  426.     if (correct)  {
  427.       alert(CORRECT_FEEDBACK);
  428.     }
  429.     else  {
  430.       var incorrect_feedback = INCORRECT_FEEDBACK;
  431.       if (!use_default)
  432.         incorrect_feedback = "Incorrect. The correct answer is: '" + correct_ans_obj.value + "'";
  433.       alert(incorrect_feedback);
  434.     }
  435.   }
  436. }
  437.  
  438. function correct_ans(answer_obj,quest_id)
  439. {
  440.   var correct_ans = "";
  441.   var correct_ans_num = Math.floor(((1 / (EXT_VALUE / 1000000)) / 3) / quest_id);
  442.   switch (correct_ans_num)
  443.   {
  444.       case 1:
  445.           correct_ans = "A";
  446.           break;
  447.       case 2:
  448.           correct_ans = "B";
  449.           break;
  450.       case 3:
  451.           correct_ans = "C";
  452.           break;
  453.       case 4:
  454.           correct_ans = "D";
  455.           break;
  456.     case 5:
  457.           correct_ans = "E";
  458.           break;
  459.   }
  460.  
  461.   return correct_ans;
  462. }
  463.  
  464. function write_media()
  465. {
  466.   if (ENABLE_AUDIO) {
  467.     document.write(MEDIA_HTML);
  468.   }
  469. }
  470.  
  471. function flash_command(command_str)
  472. {
  473.   eval(command_str);
  474. }
  475.  
  476. function goto_sco(tmp_sco,tmp_folder)
  477. {
  478.   if ((API_WIN.FILE_LMS) || (API_WIN.RUN_TYPE == "flms"))
  479.     API_WIN.flms_sco_finish("../" + tmp_folder + "/start.htm?filelms=1&sco=" + tmp_sco);
  480. }
  481.  
  482.  
  483.